package com.aaa.whj.controller;


import com.aaa.sys.entity.TabUser;
import com.aaa.whj.entity.Scl;
import com.aaa.whj.entity.TabReturn;
import com.aaa.whj.service.TabReturnService;
import com.aaa.whj.service.impl.TabReturnServiceImpl;
import com.util.LayData;
import com.util.PrintJsonData;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * (TabReturn)表控制层
 *
 * @author makejava
 * @since 2023-05-12 11:29:26
 */


@WebServlet(name = "TabReturnServlet", value = "/TabReturnServlet")
public class TabReturnServlet extends HttpServlet {

    private final TabReturnService tabReturnService = new TabReturnServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 
        String method = req.getParameter("method");
        if (method==null){

        }else if(method.equals("findAll")){
            query(req,resp);
            return;
        }else if(method.equals("add")){
            add(req,resp);
            return;
        }else if(method.equals("upd")){
            upd(req,resp);
            return;
        }else if(method.equals("del")){
            del(req,resp);
            return;
        }

    }

  

    private void del(HttpServletRequest req, HttpServletResponse resp) {
    }

    private void upd(HttpServletRequest req, HttpServletResponse resp) {
    }

    private void add(HttpServletRequest req, HttpServletResponse resp) {
        String id = req.getParameter("id");

        String name = req.getParameter("name");

        String tel = req.getParameter("tel");

        String plan_name = req.getParameter("plan_name");

        String re_con = req.getParameter("re_con");

        String re_bei = req.getParameter("re_bei");

        HttpSession session = req.getSession();
        TabUser user = (TabUser) session.getAttribute("user");

        TabReturn tabReturn=new TabReturn(id,name,tel,plan_name,re_con,re_bei,user.getUsername());

        TabReturn insert = tabReturnService.insert(tabReturn);
        LayData success = LayData.success(null);
        PrintJsonData.printData(resp,success);


    }

    private void query(HttpServletRequest req, HttpServletResponse resp) {
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        List<TabReturn> tabReturns = tabReturnService.queryAll(page, limit);
        //System.out.println("scl = " + scl);
        long count = tabReturnService.count1(null);
        //System.out.println("count = " + count);
        LayData success = LayData.success((int) count, tabReturns);
        PrintJsonData.printData(resp,success);
    }
}




